package mo.offer_special;

import java.util.Comparator;
import java.util.TreeSet;

public class L058 {

    TreeSet<int[]> booked;

    public L058() {
        booked = new TreeSet<>(Comparator.comparingInt(a -> a[0]));
    }

    public boolean book(int start, int end) {
        if (booked.isEmpty()) {
            booked.add(new int[]{start, end});
            return true;
        }
        int[] tmp = {end, 0};
        int[] arr = booked.ceiling(tmp);
        if (arr == booked.first() || (booked.lower(tmp) != null && booked.lower(tmp)[1] <= start)) {
            booked.add(new int[]{start, end});
            return true;
        }
        return false;
    }

}
